home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / java / io / PipedWriter.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  1.2 KB  |  70 lines

  1. package java.io;
  2.  
  3. public class PipedWriter extends Writer {
  4.    private PipedReader sink;
  5.    private boolean closed = false;
  6.  
  7.    public PipedWriter(PipedReader var1) throws IOException {
  8.       this.connect(var1);
  9.    }
  10.  
  11.    public PipedWriter() {
  12.    }
  13.  
  14.    public synchronized void connect(PipedReader var1) throws IOException {
  15.       if (var1 == null) {
  16.          throw new NullPointerException();
  17.       } else if (this.sink == null && !var1.connected) {
  18.          if (!var1.closedByReader && !this.closed) {
  19.             this.sink = var1;
  20.             var1.in = -1;
  21.             var1.out = 0;
  22.             var1.connected = true;
  23.          } else {
  24.             throw new IOException("Pipe closed");
  25.          }
  26.       } else {
  27.          throw new IOException("Already connected");
  28.       }
  29.    }
  30.  
  31.    public void write(int var1) throws IOException {
  32.       if (this.sink == null) {
  33.          throw new IOException("Pipe not connected");
  34.       } else {
  35.          this.sink.receive(var1);
  36.       }
  37.    }
  38.  
  39.    public void write(char[] var1, int var2, int var3) throws IOException {
  40.       if (this.sink == null) {
  41.          throw new IOException("Pipe not connected");
  42.       } else if ((var2 | var3 | var2 + var3 | var1.length - (var2 + var3)) < 0) {
  43.          throw new IndexOutOfBoundsException();
  44.       } else {
  45.          this.sink.receive(var1, var2, var3);
  46.       }
  47.    }
  48.  
  49.    public synchronized void flush() throws IOException {
  50.       if (this.sink != null) {
  51.          if (this.sink.closedByReader || this.closed) {
  52.             throw new IOException("Pipe closed");
  53.          }
  54.  
  55.          synchronized(this.sink) {
  56.             this.sink.notifyAll();
  57.          }
  58.       }
  59.  
  60.    }
  61.  
  62.    public void close() throws IOException {
  63.       this.closed = true;
  64.       if (this.sink != null) {
  65.          this.sink.receivedLast();
  66.       }
  67.  
  68.    }
  69. }
  70.